/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.GUI;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.Node;
import javafx.scene.control.Label;

/**
 *
 * @author Vi
 */
public class ValidationForm {

    protected List<Boolean> correctField = new ArrayList<>();
    protected ArrayList<Node> inputs = new ArrayList<>();
    protected ArrayList<Label> labels = new ArrayList<>();

    protected void makeList(int size) {
        correctField.clear();

        for (int i = 0; i < size; i++) {
            correctField.add(Boolean.TRUE);
        }
    }

    protected void printValidator(List<Boolean> list) {
        int i = 0;
        for (Boolean b : list) {
            System.out.println(i + " " + b.toString());
            i++;
        }
    }

    protected void checkDouble(String s, int i) {
        System.out.println("employment " + s);
        if (s.isEmpty()) {
            correctField.set(i, Boolean.FALSE);
            System.out.println("false double");

        } else {
            try {
                Double.parseDouble(s);
                correctField.set(i, Boolean.TRUE);
                System.out.println("true double");
            } catch (Exception e) {
                correctField.set(i, Boolean.FALSE);
                System.out.println("false double");
            }
        }
    }

    protected void checkDate(String s, int i) {

        if (s.isEmpty()) {
            correctField.set(i, Boolean.FALSE);
        } else {
            try {
                Date.valueOf(s);
                correctField.set(i, Boolean.TRUE);
            } catch (Exception e) {
                correctField.set(i, Boolean.FALSE);
            }
        }
    }

    protected void checkString(String s, int i) {

        if (s != null) {
            if (s.isEmpty()) {
                correctField.set(i, Boolean.FALSE);
            } else {
                correctField.set(i, Boolean.TRUE);
            }
        } else {
            correctField.set(i, Boolean.FALSE);
        }

    }

    protected void setWrongTextFields(List<Boolean> textFieldsChecks) {

        int i = 0;
        for (Boolean isGood : textFieldsChecks) {
            if (isGood) {
                if (inputs.get(i).getStyleClass().remove("textFieldWrong")) {
                    inputs.get(i).getStyleClass().add("textField");
                    labels.get(i).setText("");
                }
            } else {

                if (inputs.get(i).getStyleClass().remove("textField")) {
                    inputs.get(i).getStyleClass().add("textFieldWrong");
                    labels.get(i).setText("Złe dane");
                }
            }
            i++;
        }

    }

    protected boolean isCorrect(List<Boolean> list) {
        for (Boolean el : list) {
            if (!el) {
                return false;
            }
        }
        return true;
    }

    protected String renamePosition(String polish) {

        if (polish == null) {
            return "";
        }
        if (polish.equals("Asystent oprogramowania")) {
            return "1";
        }
        if (polish.equals("Inżynier oprogramowania")) {
            return "2";
        }
        if (polish.equals("Starszy inżynier oprogramowania")) {
            return "3";
        }
        if (polish.equals("Wybierz stanowisko")) {
            return "";
        }

        return polish;
    }
    
    protected String namePosition(String number) {
        
        if (number.equals("1")) {
            return "Asystent oprogramowania";
        }
        else if (number.equals("2")) {
            return "Inżynier oprogramowania";
        }
        else if (number.equals("3")) {
            return "Starszy inżynier oprogramowania";
        }
        else {
            return "Wybierz stanowisko";
        }
        
    }

    protected String renameEducation(String polish) {
        if (polish == null) {
            return "";
        }
        if (polish.equals("Wybierz wykształcenie")) {
            return "";
        }
        if (polish.equals("Inżynier/licencjat")) {
            return "1";
        }
        if (polish.equals("Magister")) {
            return "2";
        }
        if (polish.equals("Doktor")) {
            return "3";
        }

        return polish;
    }
    
    protected String nameEducation(String number) {
        
        if (number.equals("1")) {
            return "Inżynier/licencjat";
        }
        else if (number.equals("2")) {
            return "Magister";
        }
        else if (number.equals("3")) {
            return "Doktor";
        }
        else {
            return "Wybierz wykształcenie";
        }
        
    }

    protected String renameCertifacations(String polish) {
        if (polish == null) {
            return "";
        }
        if (polish.equals("Liczba certyfikatów")) {
            return "";
        }
        if (polish.equals("0")) {
            return "0";
        }
        if (polish.equals("1")) {
            return "0.5";
        }
        if (polish.equals("2")) {
            return "1.0";
        }
        if (polish.equals("3")) {
            return "1.5";
        }
        return polish;
    }
    
    protected String nameCertifications(String number) {
        
        if (number.equals("0")) {
            return "0";
        }
        else if (number.equals("0.5")) {
            return "1";
        }
        else if (number.equals("1.0")) {
            return "2";
        }
        else if (number.equals("1.5")) {
            return "3";
        }
        else {
            return "Liczba certyfikatów";
        }
        
    }

    protected void checkInteger(String s, int i) {

        if (s.isEmpty()) {
            correctField.set(i, Boolean.FALSE);

        } else {
            try {
                Integer.parseInt(s);
                correctField.set(i, Boolean.TRUE);
            } catch (Exception e) {
                correctField.set(i, Boolean.FALSE);
            }
        }
    }
}
